package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.MyCollection;
import cn.wolfcode.trip.base.query.MyCollectionQueryObject;
import cn.wolfcode.trip.base.service.IMyCollectionService;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/myCollections")
public class CollectionController {
    @Autowired
    private IMyCollectionService collectionService;

    /**
     * 收藏
     * @param collection
     * @return
     */
    @PostMapping
    public JSONResult addCollection(MyCollection collection) {
        JSONResult result = new JSONResult();
        try {
            collectionService.save(collection);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }

    /**
     * 取消收藏
     * @param strategydetailId
     * @param travelId
     * @param dailyId
     * @param userId
     * @return
     */
    @DeleteMapping
    public JSONResult deleteCollection(Long strategydetailId, Long travelId, Long dailyId, Long userId) {
        JSONResult result = new JSONResult();
        try {
            collectionService.delete(strategydetailId, travelId, dailyId, userId);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }

    /**
     * 查看当前用户是否对当前内容已经收藏了
     * @param strategydetailId
     * @param travelId
     * @param dailyId
     * @param userId
     * @return
     */
    @GetMapping
    public Boolean checkHasCollection(Long strategydetailId, Long travelId, Long dailyId, Long userId){
        return collectionService.checkHasCollection(strategydetailId, travelId, dailyId, userId);
    }

    /**
     * 查询所有的收藏数
     * @return
     */
    @GetMapping("/selectCollection")
    public Integer selectCollection(MyCollectionQueryObject qo){
        return collectionService.selectCollection(qo);
    }

    @GetMapping("/travelAll")
    public Integer selecttravelId(MyCollectionQueryObject qo){
        return collectionService.selecttravelId(qo);
    }

    @GetMapping("/strategydetaiAll")
    public Integer selectstrategydetaiId(MyCollectionQueryObject qo){
        return collectionService.selectstrategydetaiId(qo);
    }

    @GetMapping("/dailyAll")
    public Integer selectdailyId(MyCollectionQueryObject qo){
        return collectionService.selectdailyId(qo);
    }
}
